#!/bin/bash
# 1.hive导入mysql
# 连接信息
jdbc_url="jdbc:mysql://localhost:3306/jingdong"
user="root"
pwd="root"
hive_db_dir="/user/hive/warehouse/jingdong.db"
idx=0

function export_hive_to_mysql() {
  tbl=$1
  idx=$((idx+1))
  echo "----------------------------- export 第[$idx]个, table:[$tbl] start -----------------------------"
  sqoop export \
  -Dsqoop.export.records.per.statement=100 \
  --batch \
  --num-mappers 1 \
  --connect $jdbc_url \
  --username $user \
  --password $pwd \
  --table $tbl \
  --export-dir $hive_db_dir/$tbl \
  --input-fields-terminated-by ','
  echo "----------------------------- export 第[$idx]个, table:[$tbl] finish -----------------------------"
  sleep 3
}
# 导入数据
export_hive_to_mysql after_sales_count
export_hive_to_mysql average_price
export_hive_to_mysql city_order_count
export_hive_to_mysql daily_completed_order_count
export_hive_to_mysql daily_order_count
export_hive_to_mysql daily_return_rate
export_hive_to_mysql daily_returned_order_count
export_hive_to_mysql daily_sales_sum
export_hive_to_mysql member_order_count
export_hive_to_mysql model_province_sales_count
export_hive_to_mysql model_sales_count
export_hive_to_mysql province_order_count
export_hive_to_mysql student_order_count
export_hive_to_mysql order_category_sum

echo "export [$idx] tables."
sleep 5
# 删除无用文件
rm -f *.java
echo "export done!!!"